<?php
class settingAction extends runAction{

	public function index() {
		C ( 'SHOW_RUN_TIME', false );
		C ( 'SHOW_PAGE_TRACE', false );
		
		$this->display ();
	}
	public function save() {
		
		$act = $_POST ['act'];
		if ($act == '测试') {
			R ( MODULE_NAME, 'smtp_run' );
			exit ();
		}
		
		$txt = file_get_contents ( 'config.php' );
		
		foreach ( $_POST as $k => $v ) {
			
			if (strpos ( $k, '__' ) !== false) {
				continue;
			}
			
			$a = array ('\"', "'" );
			$b = array ('"', "\'" );
			$v = str_replace ( $a, $b, $v );
			
			
			$txt = preg_replace ( "/'$k'	=> \'(.*)\',/", "'$k'	=> '$v',", $txt );
		
		}
		
		$fo = fopen ( 'config.php', 'w' );
		$st = fwrite ( $fo, $txt );
		fclose ( $fo );
		
		if ($st !== false) {
			
			//清Runtime
			import ( 'app.ORG.cleanRuntime' );
			cleanRuntime::go ();
			$this->assign('jUrl',$_SERVER['HTTP_REFERER']);
			$this->success ( '保存成功' );
		} else {
			$this->assign('jUrl',$_SERVER['HTTP_REFERER']);
			$this->error ( '保存失败' );
		}
	}
	public function cleanruntime() {

		import ( 'app.ORG.cleanRuntime' );
		$st = cleanRuntime::go ();
		
		if ($st) {
			$this->assign('jUrl',$_SERVER['HTTP_REFERER']);
			$this->success ( '清理完成' );
		}
	}
	public function smtp_run() {
		
		import ( 'app.ORG.smtp' );
		
		$smtp = smtp::connect ();
		$arr = array (
		'obj'		=> $smtp,
		'to'		=> C( 'SMTP_TO' ),
		'subject'	=> 'SMTP邮件发送测试',
		'content'	=> '当您看到这个邮件，代表SMTP已配置成功' );
		$st = smtp::send ( $arr );
		smtp::close ( $smtp );
		
		
		if ($st){
			$this->success ( '验证邮件已发送' );
		}
		else{
			$this->error ( '邮件发送失败' );
		}
	}
}
?>